<?php
class FCKeditorForm extends PostBackControl {

	var $ConfigurationManager;
	var $LanguageSelect;
	var $LanguageDirectionSelect;
	var $LinkTargetSelect;
	var $LanguageArray;
	var $SkinSelect;
	var $EnterModeSelect;
	var $ShiftEnterModeSelect;
	var $ToolbarSelect;

	function FCKeditorForm(&$Context) {
		$this->Name = 'FCKeditorForm';
		$this->ValidActions = array('FCKeditorPreference','ProcessFCKeditorPreference');
		$this->LanguageArray = array("af"=>"Afrikaans (af)","ar"=>"Arabic (ar)","eu"=>"Basque (eu)","bn"=>"Bengali/Bangla (bn)","bs"=>"Bosnian (bs)","bg"=>"Bulgarian (bg)","ca"=>"Catalan (ca)","zh-cn"=>"Chinese Simplified (zh-cn)","zh"=>"Chinese Traditional (zh)","hr"=>"Croatian (hr)","cs"=>"Czech (cs)","da"=>"Danish (da)","nl"=>"Dutch (nl)","en"=>"English (en)","en-au"=>"English (Australia) (en-au)","en-ca"=>"English (Canadian) (en-ca)","en-uk"=>"English (United Kingdom) (en-uk)","eo"=>"Esperanto (eo)","et"=>"Estonian (et)","fo"=>"Faroese (fo)","fi"=>"Finnish (fi)","fr"=>"French (fr)","gl"=>"Galician (gl)","de"=>"German (de)","el"=>"Greek (el)","he"=>"Hebrew (he)","hi"=>"Hindi (hi)","hu"=>"Hungarian (hu)","it"=>"Italian (it)","ja"=>"Japanese (ja)","km"=>"Khmer (km)","ko"=>"Korean (ko)","lv"=>"Latvian (lv)","lt"=>"Lithuanian (lt)","ms"=>"Malay (ms)","mn"=>"Mongolian (mn)","no"=>"Norwegian (no)","nb"=>"Norwegian Bokmal (nb)","fa"=>"Persian (fa)","pl"=>"Polish (pl)","pt-br"=>"Portuguese (Brazil) (pt-br)","pt"=>"Portuguese (Portugal) (pt)","ro"=>"Romanian (ro)","ru"=>"Russian (ru)","sr"=>"Serbian (Cyrillic) (sr)","sr-latn"=>"Serbian (Latin) (sr-latn)","sk"=>"Slovak (sk)","sl"=>"Slovenian (sl)","es"=>"Spanish (es)","sv"=>"Swedish (sv)","th"=>"Thai (th)","tr"=>"Turkish (tr)","uk"=>"Ukrainian (uk)","vi"=>"Vietnamese (vi)");
		$this->Constructor($Context);

		if($this->IsPostBack)
		{	$SettingsFile = $this->Context->Configuration['APPLICATION_PATH'].'conf/settings.php';
			$this->ConfigurationManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'ConfigurationManager');
			
			if ($this->PostBackAction == 'ProcessFCKeditorPreference')
			{
				$this->ConfigurationManager->GetSettingsFromForm($SettingsFile);
				$this->ConfigurationManager->DefineSetting('FCKEDITOR_UPLOAD_PATH', ForceIncomingString('FCKEDITOR_UPLOAD_PATH', 'uploads/%userid%/'), 0);
				$this->ConfigurationManager->DefineSetting('FCKEDITOR_DEFAULT_LANGUAGE', ForceIncomingString('FCKEDITOR_DEFAULT_LANGUAGE', 'en'), 0);
				$this->ConfigurationManager->DefineSetting('FCKEDITOR_LANGUAGE_DIRECTION', ForceIncomingString('FCKEDITOR_LANGUAGE_DIRECTION', 'ltr'), 0);
				$this->ConfigurationManager->DefineSetting('FCKEDITOR_DEFAULT_SKIN', ForceIncomingString('FCKEDITOR_DEFAULT_SKIN', 'silver'), 0);
				$this->ConfigurationManager->DefineSetting('FCKEDITOR_SHOW_BLOCKS', ForceIncomingString('FCKEDITOR_SHOW_BLOCKS', 'false'), 0);
				$this->ConfigurationManager->DefineSetting('FCKEDITOR_ENTERMODE', ForceIncomingString('FCKEDITOR_ENTERMODE', 'br'), 0);
				$this->ConfigurationManager->DefineSetting('FCKEDITOR_SHIFT_ENTERMODE', ForceIncomingString('FCKEDITOR_SHIFT_ENTERMODE', 'p'), 0);
				$this->ConfigurationManager->DefineSetting('FCKEDITOR_DEFAULT_LINK_TARGET', ForceIncomingString('FCKEDITOR_DEFAULT_LINK_TARGET', '_blank'), 0);
				$this->ConfigurationManager->DefineSetting('FCKEDITOR_FILEMANAGER', ForceIncomingString('FCKEDITOR_FILEMANAGER', 'false'), 0);
				$this->ConfigurationManager->DefineSetting('FCKEDITOR_IMAGE', ForceIncomingString('FCKEDITOR_IMAGE', 'false'), 0);
				$this->ConfigurationManager->DefineSetting('FCKEDITOR_FLASH', ForceIncomingString('FCKEDITOR_FLASH', 'false'), 0);
				$this->ConfigurationManager->DefineSetting('FCKEDITOR_LINK', ForceIncomingString('FCKEDITOR_LINK', 'false'), 0);
				$this->ConfigurationManager->DefineSetting('FCKEDITOR_IMAGE_ALLOWED_EXTENSIONS', ForceIncomingString('FCKEDITOR_IMAGE_ALLOWED_EXTENSIONS', ''), 0);
				$this->ConfigurationManager->DefineSetting('FCKEDITOR_FLASH_ALLOWED_EXTENSIONS', ForceIncomingString('FCKEDITOR_FLASH_ALLOWED_EXTENSIONS', ''), 0);
				$this->ConfigurationManager->DefineSetting('FCKEDITOR_LINK_ALLOWED_EXTENSIONS', ForceIncomingString('FCKEDITOR_LINK_ALLOWED_EXTENSIONS', ''), 0);				
				$this->ConfigurationManager->DefineSetting('FCKEDITOR_PLUGIN_VIDEO', ForceIncomingString('FCKEDITOR_PLUGIN_VIDEO', 'true'), 0);
				
				if ($this->ConfigurationManager->SaveSettingsToFile($SettingsFile)) {
					header('Location: '.GetUrl($this->Context->Configuration, 'settings.php', '', '', '', '', 'PostBackAction=FCKeditorPreference&Success=1'));
				} else {
					$this->PostBackAction = 'FCKeditorPreference';
				}
			}
		}
	}
	function RenderLanguageSelect(){
		$this->ConfigurationManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'ConfigurationManager');
		$this->LanguageSelect = $this->Context->ObjectFactory->NewObject($this->Context, 'Select');
		$this->LanguageSelect->Name = 'FCKEDITOR_DEFAULT_LANGUAGE';
		$this->LanguageSelect->CssClass = 'SmallInput';
		$this->LanguageSelect->AddOptionsFromAssociativeArray($this->LanguageArray ,'');
		$this->LanguageSelect->SelectedValue = $this->ConfigurationManager->GetSetting('FCKEDITOR_DEFAULT_LANGUAGE');
	}
	function RenderLanguageDirectionSelect(){
		$this->ConfigurationManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'ConfigurationManager');
		$this->LanguageDirectionSelect = $this->Context->ObjectFactory->NewObject($this->Context, 'Select');
		$this->LanguageDirectionSelect->Name = 'FCKEDITOR_LANGUAGE_DIRECTION';
		$this->LanguageDirectionSelect->CssClass = 'SmallInput';
		$this->LanguageDirectionSelect->AddOptionsFromAssociativeArray(array("ltr"=>"LTR (English etc)","rtl"=>"RTL (Arabic etc)") ,'');
		$this->LanguageDirectionSelect->SelectedValue = $this->ConfigurationManager->GetSetting('FCKEDITOR_LANGUAGE_DIRECTION');
	}
	function RenderLinkTargetSelect(){
		$this->ConfigurationManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'ConfigurationManager');
		$this->LinkTargetSelect = $this->Context->ObjectFactory->NewObject($this->Context, 'Select');
		$this->LinkTargetSelect->Name = 'FCKEDITOR_DEFAULT_LINK_TARGET';
		$this->LinkTargetSelect->CssClass = 'SmallInput';
		$this->LinkTargetSelect->AddOptionsFromAssociativeArray(array("_blank"=>"New Window (_blank)","_self"=>"Same Window (_self)","_parent"=>"Parent Window (_parent)") ,'');
		$this->LinkTargetSelect->SelectedValue = $this->ConfigurationManager->GetSetting('FCKEDITOR_DEFAULT_LINK_TARGET');
	}
	function RenderSkinSelect(){
		$this->ConfigurationManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'ConfigurationManager');
		$this->SkinSelect = $this->Context->ObjectFactory->NewObject($this->Context, 'Select');
		$this->SkinSelect->Name = 'FCKEDITOR_DEFAULT_SKIN';
		$this->SkinSelect->CssClass = 'SmallInput';
		$this->SkinSelect->AddOptionsFromAssociativeArray(array("default"=>"Default","silver"=>"Silver","office2003"=>"office 2003") ,'');
		$this->SkinSelect->SelectedValue = $this->ConfigurationManager->GetSetting('FCKEDITOR_DEFAULT_SKIN');
	}
	function RenderEnterModeSelect(){
		$this->ConfigurationManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'ConfigurationManager');
		$this->EnterModeSelect = $this->Context->ObjectFactory->NewObject($this->Context, 'Select');
		$this->EnterModeSelect->Name = 'FCKEDITOR_ENTERMODE';
		$this->EnterModeSelect->CssClass = 'SmallInput';
		$this->EnterModeSelect->AddOptionsFromAssociativeArray(array("br"=>"Break tag <br />","p"=>"Paragraph tag <p>","div"=>"Div tag <div>") ,'');
		$this->EnterModeSelect->SelectedValue = $this->ConfigurationManager->GetSetting('FCKEDITOR_ENTERMODE');
	}
	function RenderShiftEnterModeSelect(){
		$this->ConfigurationManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'ConfigurationManager');
		$this->ShiftEnterModeSelect = $this->Context->ObjectFactory->NewObject($this->Context, 'Select');
		$this->ShiftEnterModeSelect->Name = 'FCKEDITOR_SHIFT_ENTERMODE';
		$this->ShiftEnterModeSelect->CssClass = 'SmallInput';
		$this->ShiftEnterModeSelect->AddOptionsFromAssociativeArray(array("br"=>"Break tag <br />","p"=>"Paragraph tag <p>","div"=>"Div tag <div>") ,'');
		$this->ShiftEnterModeSelect->SelectedValue = $this->ConfigurationManager->GetSetting('FCKEDITOR_SHIFT_ENTERMODE');
	}
	function RenderToolbarSelect(){
		$this->ConfigurationManager = $this->Context->ObjectFactory->NewContextObject($this->Context, 'ConfigurationManager');
		$this->ToolbarSelect = $this->Context->ObjectFactory->NewObject($this->Context, 'Select');
		$this->ToolbarSelect->Name = 'FCKEDITOR_DEFAULT_TOOLBAR';
		$this->ToolbarSelect->CssClass = 'SmallInput';
		$this->ToolbarSelect->AddOptionsFromAssociativeArray(array("Vanilla"=>"Vanilla (Default)","Basic"=>"Basic") ,'');
		$this->ToolbarSelect->SelectedValue = $this->ConfigurationManager->GetSetting('FCKEDITOR_DEFAULT_TOOLBAR');
	}	

	function Render() {
		$this->RenderLanguageSelect();
		$this->RenderLanguageDirectionSelect();
		$this->RenderLinkTargetSelect();
		$this->RenderSkinSelect();
		$this->RenderEnterModeSelect();
		$this->RenderShiftEnterModeSelect();
		$this->RenderToolbarSelect();
		
		if ($this->IsPostBack)
		{
			$this->PostBackParams->Clear();
			if ($this->PostBackAction == 'FCKeditorPreference')
			{
				$this->PostBackParams->Set('PostBackAction', 'ProcessFCKeditorPreference');
				include(FCKEDITOR_PATH.'Theme.FCKeditorForm.php');
			}
		}
	}
}
?>